﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WebSite.Master" AutoEventWireup="true"
    CodeBehind="UserInfo.aspx.cs" Inherits="RN.ERP.Web.Manage.UserInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="Stylesheet" type="text/css" href="../Scripts/ligerUI/skins/Aqua/css/ligerui-all.css" />
    <link href="../Styles/skins/blue/css/style.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/skins/blue/css/style_msg.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/ligerui.min.js"></script>
    <script src="../Scripts/ligerUI/js/common.js" type="text/javascript"></script>
    <script src="../Scripts/ligerUI/js/LG.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/plugins/ligerGrid.js"></script>
    <script type="text/javascript" src="../Scripts/ligerUI/js/plugins/ligerLayout.js"></script>
    <script type="text/javascript" language="javascript">
        var selectedUserID, selectedRoleID;
        var gridRole, gridUser;
        var gridRight;
        var bottomHeader;
        $(function () {
            var layout = $("#layout").ligerLayout({
                bottomHeight: $(window).height() - 370,
                heightDiff: -6
            });

            bottomHeader = $(".l-layout-bottom > .l-layout-header:first");
            var tab = $("#tabcontainer").ligerTab();

            var toolbarOptionsRole = {
                items: [
                { text: '添加', click: f_addRole, img: "../images/addicon.jpg" }
                ]
            };

            function f_addRole() {
                window.location.href = "RoleList.aspx";
            }

            gridRole = $("#rolegrid").ligerGrid({
                columns:
                [
                { display: '角色名', name: 'Title', width: 150, align: 'left' },
                { display: '角色编号', name: 'Code', width: 150, align: 'left' },
                { display: '角色地区', name: 'AreaCode', width: 150, align: 'left' },
                { display: '角色描述', name: 'Description', width: 450, align: 'left' }
                ], showToggleColBtn: false, width: '97%', height: 290, rowHeight: 20, fixedCellHeight: true, pageSize: 9,
                columnWidth: 100, frozen: false, sortName: 'Title', checkbox: false, rownumbers: true, toolbar: toolbarOptionsRole,
                data: []
            });

            $.ajax({
                type: 'get',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=getroles&r=' + Math.random(),
                success: function (result) {
                    gridRole.set('data', { Rows: result });
                }
            });

            $.ajax({
                type: 'get',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=getperusers&name=&username=&r=' + Math.random(),
                success: function (result) {
                    gridUser.set('data', { Rows: result });
                }
            });

            gridRole.bind('SelectRow', function (rowdata) {
                selectedUserID = null;
                selectedRoleID = rowdata.Id;
                bottomHeader.html("设置角色【" + rowdata.Title + "】的权限");

                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getfunc&roleID=' + selectedRoleID + '&r=' + Math.random(),
                    success: function (result) {
                        gridRight.set('data', { Rows: result });
                    }
                });
            });

            var toolbarOptions = {
                items: [
                { text: '保存', click: f_save, img: "../images/page_save.png" }
                ]
            };

            ////初始化菜单
            gridRight = $("#rightgrid").ligerGrid({
                columns:
                [
                { display: '分配权限', name: 'Permit', align: 'left', width: 60, minWidth: 60, isAllowHide: false, render: function (rowdata) {
                    var iconHtml = '<div class="access-icon access-permit';
                    if (rowdata.Permit) iconHtml += " access-icon-selected";
                    iconHtml += '"';
                    iconHtml += ' rowid = "' + rowdata['__id'] + '"';
                    iconHtml += ' onclick="clickcheck(this)"></div>';
                    return iconHtml;
                }
                },
                { display: '菜单', name: 'AccessName', align: 'left', width: 200, minWidth: 60 },
                { display: '编码', name: 'AccessNo', align: 'left', width: 100, minWidth: 60 },
                { display: 'AppID', name: 'AccessAppID', align: 'left', width: 100, minWidth: 60 },
                { display: '地址', name: 'AccessUrl', align: 'left', width: 550, minWidth: 60 },
                { display: '描述', name: 'DESCRIPTION', align: 'left', width: 150, minWidth: 60 }
                ], showToggleColBtn: false, width: '97%', height: '45%', rowHeight: 20, fixedCellHeight: true,
                columnWidth: 100, frozen: false, usePager: false, checkbox: false, rownumbers: true, toolbar: toolbarOptions, sortName: 'SortIndex',
                tree: { columnName: 'AccessName' },
                data: []
            });

            getfunc();

            //用户,在tab选择的时候才加载表格和表格数据
            tab.bind('afterSelectTabItem', function (tabid) {
                bottomHeader.html("权限控制");
                getfunc();
                if (tabid != "userlist") {
                    gridRole.loadData();
                    return;
                }
                //用户
                gridUser = $("#usergrid").ligerGrid({
                    columns:
                [
                { display: '名称', name: 'CorpName', align: 'left', width: 220, minWidth: 60 },
                { display: '用户名', name: 'UserName', align: 'left', width: 200, minWidth: 60 },
                { display: '角色', name: 'RoleID', align: 'left', width: 200, minWidth: 60 },
                { display: '角色地区', name: 'AreaCode', align: 'left', width: 200, minWidth: 60 },
                { display: '设置角色', isAllowHide: false, width: "100",
                    render: function (rowdata) {
                        var html = '<a href="BidUserRole.aspx?UserGuid=' + rowdata.CorpUserGuid + '&UserName=' + rowdata.CorpName + '" target="_blank">绑定（修改）</a>';
                        return html;
                    }
                }
                ], showToggleColBtn: false, width: '97%', rowHeight: 20, fixedCellHeight: true, pageSize: 10, height: '46%',
                    columnWidth: 100, frozen: false, sortName: 'CorpUserGuid', checkbox: false, rownumbers: true,
                    data: []
                });
                var name = $("#txtName").val();
                var username = $("#txtUserName").val();
                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getperusers&name=' + escape(name) + '&username=' + escape(username) + '&r=' + Math.random(),
                    success: function (result) {
                        gridUser.set('data', { Rows: result });
                    }
                });
                gridUser.bind('SelectRow', function (rowdata) {
                    selectedUserID = rowdata.CorpUserGuid;
                    selectedRoleID = null;

                    bottomHeader.html("给用户【" + rowdata.CorpName + "】 单独设置权限");
                    //---修改单个用户
                    $.ajax({
                        type: 'get',
                        cache: false,
                        dataType: 'json',
                        url: '../handlers/AuthorityHandler.ashx?act=getfuncforuser&userID=' + selectedUserID + '&roleID=' + selectedRoleID + '&r=' + Math.random(),
                        success: function (result) {
                            gridRight.set('data', { Rows: result });
                        }
                    });
                });
            });

            $("#btnSearch").click(function () {
                var name = $("#txtName").val();
                var username = $("#txtUserName").val();
                bottomHeader.html("权限控制");
                $.ajax({
                    type: 'get',
                    cache: false,
                    dataType: 'json',
                    url: '../handlers/AuthorityHandler.ashx?act=getperusers&name=' + escape(name) + '&username=' + escape(username) + '&r=' + Math.random(),
                    success: function (result) {
                        gridUser.set('data', { Rows: result });
                        getfunc();
                    }
                });
            });
        });
        function getfunc() {
            ////加载菜单
            $.ajax({
                type: 'get',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=getfunc&r=' + Math.random(),
                success: function (result) {
                    gridRight.set('data', { Rows: result });
                }
            });
        }
        function clickcheck(data) {
            var selected = !$(data).hasClass("access-icon-selected");
            var rowid = $(data).attr("rowid");
            var rowdata = gridRight.records[rowid];
            if (selected) {
                rowdata.Permit = true;
                $(data).addClass("access-icon-selected");
            }
            else {
                rowdata.Permit = false;
                $(data).removeClass("access-icon-selected");
            }
        }
        function f_save() {
            if (!selectedRoleID && !selectedUserID) return;
            var selectedID;
            var type;
            if (selectedRoleID) {
                type = 0;
                selectedID = selectedRoleID;
            }
            else {
                type = 1;
                selectedID = selectedUserID;
            }
            var data = "";
            for (var i = 0, l = gridRight.rows.length; i < l; i++) {
                var o = $.extend({}, gridRight.rows[i]);
                o.MenuID = o.MenuID || 0;
                if (o.Permit) {
                    data = data + o.MenuID + "@";
                }
            }
            var datas = { guids: data };
            $.ajax({
                type: 'post',
                cache: false,
                dataType: 'json',
                url: '../handlers/AuthorityHandler.ashx?act=saveper&selectedID=' + selectedID + '&type=' + type + '&r=' + Math.random(),
                data: datas,
                success: function (result) {
                    LG.tip(result.Message);
                }
            });


        }

    </script>
    <style type="text/css">
        .cell-label
        {
            width: 80px;
        }
        #tabcontainer .l-tab-links
        {
            border-top: 1px solid #D0D0D0;
            border-left: 1px solid #D0D0D0;
            border-right: 1px solid #D0D0D0;
        }
        
        .projectgrid .l-selected .l-grid-row-cell, .projectgrid .l-selected
        {
            background: none;
        }
        
        .access-icon
        {
            background: url(../images/checkbox.gif) 0px 0px;
            height: 13px;
            line-height: 13px;
            width: 13px;
            margin: 4px 20px;
            display: block;
            cursor: pointer;
        }
        .access-icon-selected
        {
            background-position: 0px -13px;
        }
        .l-panel td.l-grid-row-cell-editing
        {
            padding-bottom: 2px;
            padding-top: 2px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="layout" style="margin: 2px; margin-right: 3px;">
        <div position="center" id="mainmenu" title="用户角色" style="overflow: auto;">
            <div id="tabcontainer" style="margin: 2px;">
                <div title="角色" tabid="rolelist">
                    <%--角色名：<input id="txtRoleName" type="text" />角色编号：<input id="txtRoleNum" type="text" />
                    角色地区：<input id="txtRoleArea" type="text" /><input id="btnRoleSearch" type="button" value="查询" />--%>
                    <div id="rolegrid" style="margin: 2px auto;">
                    </div>
                </div>
                <div title="用户" tabid="userlist">
                    名称：<input id="txtName" type="text" />用户名：<input id="txtUserName" type="text" /><input
                        id="btnSearch" type="button" value="查询" />
                    <div id="usergrid" style="margin: 2px auto;">
                    </div>
                </div>
            </div>
        </div>
        <div position="bottom" title="权限控制">
            <div id="rightgrid" style="margin: 2px auto;">
            </div>
        </div>
    </div>
</asp:Content>
